<template>
  <div>
    <el-dialog
      title="订单配置(谨慎修改,修改5分钟后生效,原先已发生的订单事件时间不会变)"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      :show-close="true"
      :close-on-press-escape="false"
    >
      <el-form
        :model="orderProperties"
        :rules="rules"
        label-position="right"
        ref="form"
      >
        <el-form-item label="订单超时时间（单位秒）" prop="expireCancel">
          <el-input v-model="orderProperties.expireCancel" type="number" min=0 />
        </el-form-item>
        <el-form-item label="发货后自动收货时间(单位秒)" prop="autoReceipt">
          <el-input v-model="orderProperties.autoReceipt" type="number" />
        </el-form-item>
        <el-form-item label="收货后订单自动完成时间(单位秒)" prop="autoComplete">
          <el-input v-model="orderProperties.autoComplete" type="number" />
        </el-form-item>
        <el-form-item label="发起售后售后过期时间(单位秒)" prop="expireApply">
          <el-input v-model="orderProperties.expireApply" type="number" />
        </el-form-item>
        <el-form-item label="售后等待客户填写物流时间(单位秒)" prop="waitCustomerCompleteTrank">
          <el-input v-model="orderProperties.waitCustomerCompleteTrank" type="number" />
        </el-form-item>
        <el-form-item label="售后客户填写换货物流后自动过期时间(单位秒)" prop="autoCompleteAfterCustomerTrank">
          <el-input v-model="orderProperties.autoCompleteAfterCustomerTrank" type="number" />
        </el-form-item>
        <el-form-item label="售后商家填写换货物流后自动完成时间(单位秒)" prop="autoCompleteAfterTrank">
          <el-input v-model="orderProperties.autoCompleteAfterTrank" type="number" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmClick">确 定</el-button>
        <el-button @click="cancelClick">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  // id即编辑的id，visible属性用来监听是否显示弹窗
  props: ["visible"],
  components: {},
  watch: {},
  computed: {
    dialogVisible: {
      get() {
        return this.visible;
      },
      set(value) {
        this.$emit("update:visible", value);
      }
    }
  },
  data() {
    return {
      // 弹窗相关属性
      dialogFieldBox: false,
      options: [],
      orderProperties: {
        id: null,
        expireCancel: 0,
        autoReceipt: 0,
        autoComplete: 0,
        expireApply: 0,
        waitCustomerCompleteTrank: 0,
        autoCompleteAfterCustomerTrank: 0,
        autoCompleteAfterTrank: 0
      },
      // 表单校验
      rules: {
        expireCancel: [
          {
            required: true,
            message: "订单超时时间不能为空",
            trigger: "blur"
          }
        ],
        autoReceipt: [
          {
            required: true,
            message: "发货后自动收货时间不能为空",
            trigger: "blur"
          }
        ],
        autoComplete: [
          {
            required: true,
            message: "收货后订单自动完成时间不能为空",
            trigger: "blur"
          }
        ],
        expireApply: [
          {
            required: true,
            message: "发起售后售后过期时间不能为空",
            trigger: "blur"
          }
        ],
        waitCustomerCompleteTrank: [
          {
            required: true,
            message: "售后等待客户填写物流时间不能为空",
            trigger: "blur"
          }
        ],
        autoCompleteAfterCustomerTrank: [
          {
            required: true,
            message: "售后客户填写换货物流后自动过期时间不能为空",
            trigger: "blur"
          }
        ],
        autoCompleteAfterTrank: [
          {
            required: true,
            message: "售后商家填写换货物流后自动完成时间不能为空",
            trigger: "blur"
          }
        ]
      }
    };
  },
  methods: {
    initProperties() {
      this.$https.get("order/getOrderProperties", {}).then(res => {
        this.orderProperties=res.data.data;
      });
    },
    // 确认保存
    confirmClick() {
      let param = { ...this.orderProperties };
      this.$refs.form.validate(valid => {
        if (valid) {
          this.$https.postXform("order/saveOrderProperties", param).then(res => {
            this.$message({ message: "保存成功", type: "success" });
            this.dialogVisible = false;
            this.$emit("success");
          });
        } else {
          return false;
        }
      });
    },
    cancelClick() {
      this.dialogVisible = false;
    }
  },
  mounted() {},
  created() {}
};
</script>

<style lang="less">
</style>
